use std::env;
use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::path::Path;

// 获取文件地址
fn get_file_absolute_path() -> String {
    let root_path = env::current_dir().unwrap();
    let path = Path::new(&root_path).join("storage/1.txt");
    return path.to_str().unwrap().to_string();
}

// 简洁版：使用 fs
fn read_content() -> io::Result<()> {
    let text = fs::read_to_string(path)?;
    println!("{}", text);
    Ok(())
}

fn main() -> io::Result<()> {
    let path = get_file_absolute_path();
    // Attempts to open a file in read-only mode.
    let file = File::open(path)?;
    let reader = BufReader::new(file);

    for line in reader.lines() {
        println!("{}", line?);
    }
    Ok(())
}
